package interview;

import lombok.val;

/**
 * @Author: zhangrongqing
 * @Date: 2019/11/19 19:28
 */
public class VolatileDemo {


    public static void main(String[] args) {
        ThreadDemo2 threadDemo2 = new ThreadDemo2();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(threadDemo2);
            thread.start();
        }
    }

}

class ThreadDemo2 implements Runnable {
    public volatile int count = 0;

    @Override
    public void run() {
        synchronized (this) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count = count + 1;

            System.out.println(count);
        }

    }
}

